<template>
  <div class="photoinfo-container">
    <h5>{{photoinfo.title}}</h5>
    <p class="subtitle">
      <span>发表时间:{{photoinfo.add_time | dateFormat}}</span>
      <span>点击:{{photoinfo.click}}次</span>
    </p>
    <hr />
    <!-- 缩略图区域 -->
    <div class="thumbs">
      <vue-preview :slides="list" @close="handleClose"></vue-preview>
    </div>
    <!-- 图片内容区 -->
    <div class="content" v-html="photoinfo.content"></div>

    <!-- 放置现成评论子组件 -->
    <cmt-box :id="id"></cmt-box>
  </div>
</template>

<script>
// 导入评论子组件
import comments from "../subcomponents/comments.vue";
export default {
  data() {
    return {
      id: this.$route.params.id,
      photoinfo: {},
      // 略缩图
      list: []
    };
  },
  created() {
    this.getPhotoInfo();
    this.getThumbs();
  },
  methods: {
    getPhotoInfo() {
      // 获取图片的详情
      this.$http.get("api/getimageInfo/" + this.id).then(result => {
        if (result.body.status === 0) {
          this.photoinfo = result.body.message[0];
        }
      });
    },
    // 略缩图
    handleClose() {},
    getThumbs() {
      this.$http.get("api/getthumimages/" + this.id).then(result => {
        if (result.body.status === 0) {
          // 循环每个图片，补全宽高
          result.body.message.forEach(item => {
            item.w = 600;
            item.h = 400;
            item.src = item.src; //大图
            item.msrc = item.src; //小图
          });
          this.list = result.body.message;
        }
      });
    }
  },
  components: {
    "cmt-box": comments
  }
};
</script>

<style lang="scss" scoped>
.photoinfo-container {
  padding: 3px;
  h5 {
    color: blue;
    font-size: 16px;
    text-align: center;
    margin: 15px 0;
  }
  .subtitle {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
  }
  .content {
    font-size: 12px;
    line-height: 30px;
  }
  .thumbs {
    /deep/ .my-gallery {
      //deep深层作用选择器
      display: flex;
      flex-wrap: wrap; //默认换行
      figure {
        width: 30%;
        margin: 5px;
        img {
          width: 100%;
          box-shadow: 0 0 8px #999;
          border-radius: 5px;
        }
      }
    }
  }
}
</style>